<template>
    <div>
        <Button type="success" @click="onAdd">添加</Button>
        <Button type="error" @click="onDeletes">删除多条记录</Button>
        <Input v-model="filter.name">
        <Button slot="append" icon="ios-search" @click="onSearch"></Button>
        </Input>
        <Table border :columns="columns" :data="filter.list"             @on-selection-change="onSelectionChange"></Table>
        <Page :total="filter.total" size="small"
        show-total show-elevator show-sizer
        @on-change="onChange"
        @on-page-size-change="onPageSizeChange"></Page>
        <Modal
                v-model="modal"
                title="数据操作">
            <Form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="80">
                <FormItem label="姓名" prop="name">
                    <Input v-model="formValidate.name" placeholder="请输入姓名"></Input>
                </FormItem>
                <FormItem label="密码" prop="password">
                    <Input v-model="formValidate.password" placeholder="请输入密码"></Input>
                </FormItem>
                <FormItem label="年龄" prop="age">
                    <Input v-model="formValidate.age" placeholder="请输入年龄"></Input>
                </FormItem>
                <FormItem label="地址" prop="address">
                    <Input v-model="formValidate.address" placeholder="请输入地址"></Input>
                </FormItem>
                <FormItem>
                    <Button type="primary"
                    @click="handleSubmit('formValidate')">提交</Button>
                    <Button type="ghost"
                            @click="handleReset('formValidate')"
                            style="margin-left: 8px">重置</Button>
                </FormItem>
            </Form>
        </Modal>
    </div>
</template>
<script>
    import Base from '../../common/Base';
    export default {
        mixins : [Base],
        data () {
            return {
                module : 'users',
                formValidate : {
                    name : '',
                    password : '',
                    age : '',
                    address : ''
                },
                ruleValidate : {
                    name : [
                        {required : true, message : '姓名不能为空', trigger : 'blur'}
                    ],
                    password : [
                        {required : true, message : '密码不能为空', trigger : 'blur'}
                    ],
                    //                  age:[
                    //                      {required:true,message:'年龄不能为空',trigger:'blur'}
                    //                  ],
                    address : [
                        {required : true, message : '地址不能为空', trigger : 'blur'}
                    ],
                },
                columns : [
                    {
                        type : 'selection',
                        width : 60,
                        align : 'center'
                    },
                    {
                        title : '姓名',
                        key : 'name',
                        render : (h, params) =>{
                            return h('div', [
                                h('Icon', {
                                    props : {
                                        type : 'person'
                                    }
                                }),
                                h('strong', params.row.name)
                            ]);
                        }
                    },
                    {
                        title : '密码',
                        key : 'password'
                    },
                    {
                        title : '年龄',
                        key : 'age'
                    },
                    {
                        title : '地址',
                        key : 'address'
                    },
                    {
                        title : '操作',
                        key : 'action',
                        width : 150,
                        align : 'center',
                        render : (h, params) =>{
                            return h('div', [
                                h('Button', {
                                    props : {
                                        type : 'primary',
                                        size : 'small'
                                    },
                                    style : {
                                        marginRight : '5px'
                                    },
                                    on : {
                                        click : () =>{
                                            this.show(params.row)
                                        }
                                    }
                                }, '修改'),
                                h('Button', {
                                    props : {
                                        type : 'error',
                                        size : 'small'
                                    },
                                    on : {
                                        click : () =>{
                                            this.remove(params.row._id)
                                        }
                                    }
                                }, '删除')
                            ]);
                        }
                    }
                ]
            }
        }
    }
</script>
